local niyijingsile = fk.CreateSkill{
    name = "ym2__niyijingsile",
    tags = {Skill.Compulsory},
}
Fk:loadTranslationTable{
    ["ym2__niyijingsile"] = "你已经死了！",
    [":ym2__niyijingsile"] = "锁定技，你造成的伤害不公开、不结算，直到其对受伤角色致命。",
    ["@[ym2__niyijingsile]"] = "北斗有情猛翔破",
}

Fk:addQmlMark{
    name = "ym2__niyijingsile",
    how_to_show = function (name, value, player)
        return " "
        --[[if type(value) ~= "table" then return " " end
        if (value.players == nil and Self == player) or (value.players and table.contains(value.players, Self.id)) then
            local currents = {}
            for _, element in ipairs(value.value) do
                table.insertIfNeed(currents, element)
            end
            return tostring(#currents)
        end
        return " "]]--
    end,
    qml_data = function(name, value, player)
        if type(value) ~= "table" then return { viewData = {}, numberData = {} } end
        local currents, counts = {}, {}
        for _, element in ipairs(value.value) do
            counts[tostring(element)] = (counts[tostring(element)] or 0) + 1

            table.insertIfNeed(currents, element)
        end
        return { viewData = currents, numberData = counts }
    end,
    qml_path = function(name, value, player)
        if (value.players == nil and Self == player) or (value.players and table.contains(value.players, Self.id)) then
            if type(value) == "table" and #value.value > 0 then return "packages/ym_Al/qml/niyijingsile" end
        end
        return ""
    end
}

niyijingsile:addEffect(fk.PreDamage, {
    mute = true,
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(niyijingsile.name) and data.from == player and data.skillName ~= niyijingsile.name
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@[ym2__niyijingsile]")
        mark.value = mark.value or {}
        for i = 1, data.damage, 1 do
            table.insert(mark.value, data.to.id)
        end
        room:setPlayerMark(player, "@[ym2__niyijingsile]", mark)
        data:preventDamage()
        
        local counts = {}
        for _, element in ipairs(mark.value) do
            counts[tostring(element)] = (counts[tostring(element)] or 0) + 1
        end

        if counts[tostring(data.to.id)] and counts[tostring(data.to.id)] >= data.to.hp and table.every(Fk:currentRoom().alive_players, function(p) return not p.dying end) then
            local num = counts[tostring(data.to.id)]
            while table.contains(mark.value, data.to.id) do
                table.removeOne(mark.value, data.to.id)
            end
            room:setPlayerMark(player, "@[ym2__niyijingsile]", mark)

            room:notifySkillInvoked(player, niyijingsile.name, "offensive")

            room:damage{
                damage = num,
                from = player,
                to = data.to,
                damageType = fk.NormalDamage,
                skillName = niyijingsile.name,
            }
        end
    end,
})
niyijingsile:addEffect(fk.HpChanged, {
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        if target and table.every(Fk:currentRoom().alive_players, function(p) return not p.dying end) then
            local mark = player:getTableMark("@[ym2__niyijingsile]")
            mark.value = mark.value or {}
            local counts = {}
            for _, element in ipairs(mark.value) do
                counts[tostring(element)] = (counts[tostring(element)] or 0) + 1
            end

            return counts[tostring(target.id)] and counts[tostring(target.id)] >= target.hp
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@[ym2__niyijingsile]")
        mark.value = mark.value or {}

        local counts = {}
        for _, element in ipairs(mark.value) do
            counts[tostring(element)] = (counts[tostring(element)] or 0) + 1
        end

        local num = counts[tostring(target.id)]
        while table.contains(mark.value, target.id) do
            table.removeOne(mark.value, target.id)
        end
        room:setPlayerMark(player, "@[ym2__niyijingsile]", mark)

        room:damage{
            damage = num,
            from = player,
            to = target,
            damageType = fk.NormalDamage,
            skillName = niyijingsile.name,
        }
    end,
})
niyijingsile:addAcquireEffect(function (self, player, is_start)
    player.room:setPlayerMark(player, "@[ym2__niyijingsile]", { value = {} })
end)

return niyijingsile